#!/bin/bash

CONFIG="browsershot.conf"

if [ ! -r "$CONFIG" ]; then
    echo "Could not find browsershot config file."
    exit 1
fi

. "$CONFIG"

# options may be followed by one colon to indicate they have a required argument
if ! options=$(getopt -o o:,b:,h -l ostype:,browser:,help -- "$@")
then
    # something went wrong, getopt will put out an error message for us
    exit 1
fi

set -- $options
#browser=""
#ostype=""

while [ $# -gt 0 ]
do
    case $1 in
    -o|--ostype) ostype="$2";shift;;
    -b|--browser) browser="$2";shift;;
    -h|--help) echo "Print help";;
    (--) shift; break;;
    (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
    (*) break;;
    esac
    shift
done

if [ -n "$ostype" ] 
then
	echo "OS type:" $ostype
else
	echo "Не задан параметр -o|--ostype"
	exit 1
fi

if [ -n "$browser" ] 
then
	echo "Браузер:" $browser
else
	echo "Не задан параметр -b|--browser"
	exit 1
fi

function windows {
	case $browser in
	    "'iexplore'") echo "iexplore";;
	    *) echo "Поддерживаемые браузеры для windows: iexplore"
		exit 1
	esac
}

case $ostype in
    "'windows'") windows;;
    *) echo "Поддерживаемые операционные системы: windows"
    exit 1
esac


exit 0
